//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	priority_queue<uint32_t, vector<uint32_t>, greater<uint32_t> >q;
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int op;
		cin >> op;
		if (op == 1)
		{
			uint32_t tmp;
			cin >> tmp;
			q.push(tmp);
		}
		else if (op == 2) {
			if(!q.empty())
				cout << q.top() << endl;
		}
		else if (op == 3) {
			if (!q.empty())
				q.pop();
		}
	}
	return 0;
}